home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / SAT-TCL 1.0b2 / SAT-TCLBouncingDemo ƒ / sBouncer.p < prev   
Encoding:
Text File  |  1996-06-05  |  1.8 KB  |  83 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {    sBouncer.p                                                                                                    }
  4. {}
  5. {    Sprite for the bouncer.    Based on ZScrolly from the SAT demos.                        }
  6. {}
  7. {    Copyright © 1996 by Patrick C Hew. All rights reserved.                                }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit sBouncer;
  13.  
  14. interface
  15.  
  16.     uses
  17.         SAT, BDGlobals;
  18.  
  19.     { When the bouncer hits the edge of the SAT domain , it reverses course . }
  20.     procedure HandleBouncer (me: SpritePtr);
  21.  
  22.     { A single face and set of behaviour. }
  23.     procedure SetupBouncer (me: SpritePtr);
  24.  
  25. implementation
  26.  
  27.     const
  28.         zpeedH = 1;
  29.         zpeedV = 1;
  30.  
  31.  
  32. {****************************************************}
  33. {}
  34. {    HandleBouncer                                                                                                }
  35. {}
  36. {    When the bouncer hits the edge of the SAT domain, it reverses course.            }
  37. {}
  38. {****************************************************}
  39.  
  40.     procedure HandleBouncer (me: SpritePtr);
  41.  
  42.     begin { HandleBouncer }
  43.         with me^ do begin
  44.             position.h := position.h + speed.h;
  45.             position.v := position.v + speed.v;
  46.             if position.h + 32 > gSAT.offSizeH then begin
  47.                 speed.h := -zpeedH;
  48.             end; { if }
  49.             if position.h < 0 then begin
  50.                 speed.h := zpeedH;
  51.             end; { if }
  52.             if position.v + 32 > gSAT.offSizeV then begin
  53.                 speed.v := -zpeedV;
  54.             end; { if }
  55.             if position.v < 0 then begin
  56.                 speed.v := zpeedV;
  57.             end; { if }
  58.         end; { with }
  59.     end;  { HandleBouncer }
  60.  
  61.  
  62. {****************************************************}
  63. {}
  64. {    SetupBouncer                                                                                                }
  65. {}
  66. {    A single face and set of behaviour.                                                                    }
  67. {}
  68. {****************************************************}
  69.  
  70.     procedure SetupBouncer (me: SpritePtr);
  71.  
  72.     begin { SetupBouncer }
  73.         me^.task := @HandleBouncer;
  74.         me^.face := SATGetFace(128);
  75.         me^.kind := kindBouncer;
  76.         SetRect(me^.hotRect, 0, 0, 32, 32);
  77.  
  78.         me^.speed.h := zpeedH;
  79.         me^.speed.v := -zpeedV;
  80.     end; { SetupBouncer }
  81.  
  82.  
  83. end. { sBouncer }